<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"
	import="java.util.*,com.telecom.tree.*,java.sql.*,com.telecom.cms.util.*,com.telecom.cms.dao.*,com.telecom.cms.dto.*"%>

<%@ taglib uri="/WEB-INF/tree.tld" prefix="tree"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>修改定制条件</title>
		<script type="text/javascript" src="js/dtree.js" ></script>
		<script type="text/javascript" src="js/prototype.js" ></script>

		<!--定义样式-->
		<LINK href="images/main.css" type=text/css rel=stylesheet>
		<style type="text/css">
BODY {
	SCROLLBAR-FACE-COLOR: #f2f2f2;
	SCROLLBAR-HIGHLIGHT-COLOR: #f2f2f2;
	SCROLLBAR-SHADOW-COLOR: #b7b7b7;
	SCROLLBAR-3DLIGHT-COLOR: #f2f2f2;
	SCROLLBAR-ARROW-COLOR: #999999;
	SCROLLBAR-TRACK-COLOR: #e9e9e9;
	SCROLLBAR-DARKSHADOW-COLOR: #f2f2f2;
	SCROLLBAR-BASE-COLOR: #f2f2f2;
}

.mouseOut {
	background: #FFFAFA;
	color: #000000;
}

.mouseOver {
	background: #708090;
	color: #FFFAFA;
}
</STYLE>
<script type="text/javascript">
/***********************************
此段js为ajax实现自动完成组合框
Author:王新强
Date:07-11-29
***********************************/

        var xmlHttp;
 		var completeDiv;
        var inputField;
        var nameTable;
        var nameTableBody;

        //创建XMLHttpRequest对象
        function createXMLHttpRequest() {
            if (window.ActiveXObject) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
            }
        }

        //初始化变量
        function initVars(){
         inputField = $("inputvalue");
         nameTable = $("name_table");
         completeDiv = $("popup");
         nameTableBody = $("name_table_body");
        }

        //执行方法
        function findNames(){
         initVars();
                //如果有输入值
                if (inputField.value.length > 0){
                 		createXMLHttpRequest();
                        var url = "AutoComplete?names=" + inputField.value +"&dtoId="+inputField.name;
                        xmlHttp.open("GET",url,true);
                        xmlHttp.onreadystatechange = callback;
                        xmlHttp.send(null);
                }
        }

        //回调方法
        function callback(){
        //alert(xmlHttp.status);
         if (xmlHttp.readyState == 4) {
                if (xmlHttp.status == 200){
                    var name = xmlHttp.responseXML.getElementsByTagName("name")[0].firstChild.data;
                    setNames(xmlHttp.responseXML.getElementsByTagName("name"));
                }
            }
        }

        //填充表单
        function setNames(the_names){
         clearNames();//原来的表清空
                var size = the_names.length;//匹配的个数
                //设置坐标
                setOffsets();

                var row,cel,txtNode;
                for (var i = 0; i < size; i++){
                 var nextNode = the_names[i].firstChild.data;
                 	 //nextNode = unescape(nextNode);
                        row = document.createElement("tr");//创建页面元素
                        cell = document.createElement("td");

                        cell.onmouseout = function(){this.className="mouseOut";};
                        cell.onmouseover = function(){this.className="mouseOver";};
                        cell.setAttribute("bgcolor","#FFFAFA");
                        cell.setAttribute("border","0");
                        cell.onclick = function(){populateName(this);};

                        txtNode = document.createTextNode(nextNode);
                        cell.appendChild(txtNode);//文字放入cell单元格中<TD>
                        row.appendChild(cell);//单元格放入行中<TR>
                        nameTableBody.appendChild(row);//行放入表格中<Table>
                }
        }

       //设置坐标
        function setOffsets(){
         var end = inputField.offsetWidth;
                var left = calculateOffsetLeft(inputField);
                var top = calculateOffsetTop(inputField) + inputField.offsetHeight;
                completeDiv.style.border = "black 1px solid";
                completeDiv.style.left = left +"px";
                completeDiv.style.top = top + "px";
                nameTable.style.width = end + 80 + "px";
        }

        //计算左坐标点
        function calculateOffsetLeft(field){
         return calculateOffset(field,"offsetLeft");
        }

        //计算顶坐标点
        function calculateOffsetTop(field){
         return calculateOffset(field,"offsetTop");
        }
        
        //计算坐标点
        function calculateOffset(field,attr){
  		var offset = 0;
			while(field){
	            offset += field[attr];
	            field = field.offsetParent;
            }
                
                return offset;
        }
        
        //自动完成
        function populateName(cell){
        inputField.value = cell.firstChild.nodeValue;
                clearNames();
        }
        
        //清除
        function clearNames(){
        var ind = nameTableBody.childNodes.length;
                for (var i = ind -1; i >= 0; i--){
                	nameTableBody.removeChild(nameTableBody.childNodes[i]);
                }
                completeDiv.style.border = "none";
        }
		
function subcheck(){
	var zdy=document.getElementById("yhzdycx");
	if(zdy){
		var mark="";
		var radiobutton=document.getElementsByName("radiobutton");
		for(i=0;i<4;i++){
			if(radiobutton[i].checked){
				mark=radiobutton[i].value;
			}
		}
		zdy.value=mark+" in ("+zdy.value+")";
	}
}


function changeParent(tree,nodeId){
	 aNodes = tree.aNodes;
	 truenodeid=nodeId.id.substring(tree.obj.length);
	//checked = document.getElementById(nodeId).checked;
	
	checked = nodeId.checked;
	if(checked){
		for(var i=0;i<aNodes.length;i++){
			if(aNodes[i].id == aNodes[truenodeid].pid){
				document.getElementById(tree.obj+i).checked = checked;
				changeParent(tree,document.getElementById(tree.obj+i));
				break;
			}
		}
	}else{
  	sign = 0;
		for(var i=0;i<aNodes.length;i++){
			if(aNodes[i].pid == aNodes[truenodeid].pid){
				if(document.getElementById(tree.obj+i).checked){
					sign = 1;
					break;
				}
			}
		}
		if(sign == 0){
			for(var i=0;i<aNodes.length;i++){
				if(aNodes[i].id == aNodes[truenodeid].pid){
					document.getElementById(tree.obj+i).checked = checked;
					changeParent(tree,document.getElementById(tree.obj+i));
					break;
				}
			}
		}
	}
}

function changeChild(tree,nodeId){
  //alert("tree is : "+tree.obj.length+" nodeid is :"+nodeId.id );
  //truenodeid=nodeId.id.substring(tree.obj.length);
  aNodes = tree.aNodes;
	//checked = document.getElementById(nodeId).checked;
	//alert(" nodeid is :"+nodeId );
	checked = nodeId.checked;
	//alert("tree is :  nodeid is :"+nodeId+" checked is:"+checked);
	for(var i=0;i<aNodes.length;i++){
	   // if(i>11) 
	   //   alert("pid is "+aNodes[i].pid+" & truenodeid is "+nodeId.id.substring(tree.obj.length)+" &id is "+aNodes[nodeId.id.substring(tree.obj.length)].id);
		if(aNodes[i].pid == aNodes[nodeId.id.substring(tree.obj.length)].id){
			document.getElementById(tree.obj+i).checked = checked;
			//alert(tree.obj+i);
			changeChild(tree, document.getElementById(tree.obj+i));
			//alert("return "+document.getElementById(tree.obj+i));
		}
		//else
		// alert (" why here?");
	}
}

//modify by wangxq@2007-6-15,选中单选按钮就自动选择上面的类别
function checkItem(str) 
{
  var e = window.event.srcElement; 
  //var all = eval("document.form_current_bill."+ str); 
  var all = document.getElementsByName(str); 
  for(var i=0;i<all.length;i++)
    if(all[i].value==e.name)
       all[i].checked = true;
    document.form_current_bill.submit();
}

function checkItemTextarea(str) 
{
  var e = window.event.srcElement; 
  var all = document.getElementsByName(str); 
  for(var i=0;i<all.length;i++)
    if(all[i].value==e.name)
    {
    	if(e.value!=""){
        	all[i].checked = true;
        }else if(e.value==""){
        	all[i].checked = false;
        }
    }
}

function checkItemtree() 
{
	checkItemMul('type');
}

function checkItemMul(str) 
{ 	
    var e = window.event.srcElement; 
    var all = eval("document.form_current_bill."+ str); 
    var i=0,j=0;
    for(i=0;i<all.length;i++)
      if(all[i].value==e.name)
        j=i;
    var a = document.getElementsByName(e.name); 
    if (all.length>1)
        all[j].checked = false;
    else
       	all.checked = false;
    for (i=0; i<a.length; i++) 
    { 
       if (a[i].checked)
       { 
         if (all.length>1)
            all[j].checked = true; 
         else
            all.checked = true;
         break;
       } 
    }
	if (all.length>1){
    	if(!all[j].checked)
     		document.getElementById("remove").value=e.name;
    }else{
    	if(!all.checked)
			document.getElementById("remove").value=e.name;
    }

    document.form_current_bill.submit(); 
    document.getElementById("remove").value="";
}

function upperCase(x)
{
	var y=document.getElementsByName("type");
	var e = window.event.srcElement;
	if (e.value=="")
	return;
	for(var j =0;j<y.length;j++){
	
	 if(y[j].value==x){
	 
	 y[j].checked = true;}
	}
	document.form_current_bill.submit(); 
	
}
 
function revalue(yy){

    var a = document.getElementsByName(yy);
    for(var i = 0 ; i < a.length ; i++){
    
        if(a[i].value == 99999){
        
           a[i].value = "" ;
        }
    }

}

function checkAll(str) 
{ 
  var a = document.getElementsByName(str); 
  var n = a.length;
  var o = window.event.srcElement; 
  var c = o.checked;
  for (var i=0; i<n; i++) 
     a[i].checked = c;
  if(!c){
    document.getElementById("remove").value=o.value;
  }
  document.form_current_bill.submit();
  document.getElementById("remove").value="";
} 


// end of Add by luory@2007-6-15,

function  insertvalue(o){

     var areavalue = eval('document.form_current_bill.'+o+'.value');

    
     var y=document.getElementsByName("type");

	
     var insertvalue = document.form_current_bill.inputvalue.value;
     
	 if(""!=insertvalue){
	 
     eval ('document.form_current_bill.'+o+'.value = areavalue + insertvalue +\",\"' );
     
     
          for(var j =0;j<y.length;j++){

       if(y[j].value==o){
 
             y[j].checked = true;
             document.form_current_bill.submit();
         }
       }
     }
}

function delvalue(o){
     var y=document.getElementsByName("type");
     eval('document.form_current_bill.'+o+'.value = \"\"');
     for(var j =0;j<y.length;j++){
       if(y[j].value==o){
             y[j].checked = false;
         }
       }
     document.getElementById("remove").value=o; 
     document.form_current_bill.submit();
     document.getElementById("remove").value="";
}



function clearvalue()
{
    document.form_current_bill.inputvalue.value = "";
}

function f_frameStyleResize(targObj){
  var targWin=targObj.parent.document.all[targObj.name];
  if(targWin!=null){
    var HeightValue=targObj.document.body.scrollHeight;
    targWin.style.pixelHeight=HeightValue;
  }
}
function f_iframeResize(){
  f_frameStyleResize(self);
}
window.onload=f_iframeResize;

</script>

	</head>
	<body>
		<%
			String latnid = request.getSession().getAttribute("latnid")
					.toString();
			int id = 0;
			if (null != request.getParameter("id"))
				id = Integer.parseInt(request.getParameter("id"));
			else if (null != request.getAttribute("id"))
				id = Integer.parseInt(request.getAttribute("id").toString());
		%>
		<form action="rsrecord.do"
			<%=(latnid.equals("1000") && id == 3 ? ""
							: "target='rsFrame'")%>
			name="form_current_bill" method="post" onsubmit="subcheck()">
			<div style="position: absolute; z-index: 999; overflow-y:auto; overflow-x:no; height: 100px;" id="popup">
				<table id="name_table" bgcolor="#FFFAFA" border="0" cellpadding="0"
					cellspacing="0">
					<tbody id="name_table_body">
					</tbody>
				</table>
			</div>
			<table border="0" align="center" cellpadding="1" cellspacing="1"
				width="100%" class="moduleList">
				<%
					List outputList = (List) request.getSession().getAttribute(
							"AtomList");
					List atomlist = (List) request.getAttribute("Atoms");
					if (null != request.getAttribute("AddOrModiFlag")
							&& request.getAttribute("AddOrModiFlag").toString().equals(
									"Modi")) {//By Ruyi.Luo,如果是收藏里面的修改条件，则显示一个标头
				%>
				<tr>
					<td colspan="5">
						<table width="100%" cellspacing="0" cellpadding="0" border="0">
							<tr>
								<td width="3" height="31" align="right">
									<img height="31" src="images/table_01.gif" width="3" />
								</td>
								<td background="images/table_02.gif" width="99%" height="31">
									<table cellspacing="0" cellpadding="0" align="left" border="0">
										<tbody>
											<tr>
												<td width="51" background="images/title_1_bg.gif">
													<img height="31" src="images/title_1.gif" width="51" />
												</td>
												<td width="95" background="images/title_1_bg.gif">
													<span class="color_b_666">修改定制条件</span>
												</td>
											</tr>
										</tbody>
									</table>
								</td>
								<td width="3" align="left">
									<img height="31" src="images/table_03.gif" width="3" />
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<%
					}

					ShowatomDTO sAtom = null;
					for (int j = 0; j < atomlist.size(); j++) {

						if (0 == j % 4) {
				%>

				<tr bgcolor="#FFFFFF" align=center>
					<%
								}
								SEG_BIZ_ATOM_DEFDTO dto = (SEG_BIZ_ATOM_DEFDTO) atomlist
								.get(j);

								if (null != outputList)
									for (int myi = 0; myi < outputList.size(); myi++) {
								sAtom = (ShowatomDTO) outputList.get(myi);
								if (null != sAtom
										&& sAtom.getAtomname().equals(
										dto.getBIZ_ATOM_NAME()))
									break;
								sAtom = null;
									}

								int actwidth = 190;
					%>
					<td align="center" valign="top" width="<%=actwidth%>">
						<TABLE width="100%" height="95" border=0 align="center"
							cellPadding=1 cellSpacing=0 bgColor=#d5d5d5 id=table16>
							<TR>
								<TD>
									<TABLE id=table17 cellSpacing=0 cellPadding=0 width="100%"
										bgColor=#ffffff border=0 align=center>

										<TBODY>
											<TR>
												<TD align=center>
													<TABLE id=table18 cellSpacing=0 cellPadding=3 width="100%"
														bgColor=#d5d5d5 border=0 background="images/atom_02.gif">
														<TR>
															<TD vAlign=top>
																<SPAN class=en_big><input type="checkbox"
																		id="type" name="type"
																		value="<%=dto.getBIZ_ATOM_NAME()%>"
																		<%=(null == sAtom ? "" : "checked")%>
																		onclick="checkAll('<%=dto.getBIZ_ATOM_NAME()%>')">
																	<%=dto.getBIZ_ATOM_NAME()%> </SPAN>
															</TD>
														</TR>
													</TABLE>
													<TABLE class=en_small id=table19 cellSpacing=0
														cellPadding=0 width="100%" border=0>
														<TR align="center">
															<TD height="85" colspan="3" align="center">
																<div style="height: 120px; overflow-y: auto;">
																	<table width="100%" border="0" cellspacing="0"
																		cellpadding="0">
																		<%
																										int showtypeid = dto.getSHOW_TYPE_ID();
																										String tablename = dto.getCDE_SRC_TABLE_NAME();
																										Connection con = GetConnect.getCsConnection();
																										PreparedStatement ps = null;
																										ResultSet rs = null;
																										if (100001 == showtypeid) {
																									/*	String sql = "select * from " + tablename + " order by 1";
																										ps = con.prepareStatement(sql);
																										rs = ps.executeQuery();
																										List mea = new ArrayList();
																										while (rs != null && rs.next()) {

																									MEADTO meadto = new MEADTO();
																									meadto.setITEM_ID(rs.getObject(1).toString());
																									meadto.setSTART_VAULE(rs.getString(2));
																									meadto.setEND_VALUE(rs.getString(3));
																									mea.add(meadto);
																										}
																										if (rs != null) {

																									rs.close();
																										}
																										if (ps != null) {
																									ps.close();
																										}*/

																									HashMap atommap = Initmap.getatomMap();

																									ArrayList mea = (ArrayList) atommap.get(dto
																											.getBIZ_ATOM_NAME());
																		%>
																		<tr bgcolor="#FFFFFF">
																			<td>
																				从
																				<input id="<%=dto.getBIZ_ATOM_NAME()%>"
																					name="<%=dto.getBIZ_ATOM_NAME()%>" type="text"
																					size="1" maxlength="5"
																					onchange="upperCase('<%=dto.getBIZ_ATOM_NAME()%>')">
																				到
																				<input name="<%=dto.getBIZ_ATOM_NAME()%>"
																					type="text" size="1" maxlength="5" value="99999"
																					onfocus="revalue('<%=dto.getBIZ_ATOM_NAME()%>')"
																					onchange="upperCase('<%=dto.getBIZ_ATOM_NAME()%>')">



																				<br>

																				<%
																					for (int k = 0; k < mea.size(); k++) {
																								MEADTO listdto = (MEADTO) mea.get(k);
																								String value = (listdto.getSTART_VAULE().trim() + "－" + listdto
																										.getEND_VALUE()).trim();
																				%>

																				<input type="checkbox"
																					name="<%=dto.getBIZ_ATOM_NAME()%>"
																					value="<%=value%>"
																					<%=(null != sAtom
										&& sAtom.getAtomvalue().indexOf(
												value + ",") > -1 ? "checked"
										: "")%>
																					onclick="checkItemMul('type')">
																				<%=value%>
																				<br>

																				<%
																					}

																						}

																						else if (2 == showtypeid) {

																							/*			String sql = "select * from " + tablename + " order by 1";
																									System.out.println(sql);
																									ps = con.prepareStatement(sql);
																									rs = ps.executeQuery();
																									List mea = new ArrayList();
																									while (rs != null && rs.next()) {

																								MEADTO meadto = new MEADTO();
																								meadto.setITEM_ID(rs.getObject(1).toString());
																								meadto.setSTART_VAULE(rs.getString(2));
																								meadto.setEND_VALUE("");
																								mea.add(meadto);
																									}
																									if (rs != null) {

																								rs.close();
																									}
																									if (ps != null) {
																								ps.close();
																									}  */
																							HashMap atommap = Initmap.getatomMap();

																							ArrayList mea = (ArrayList) atommap.get(dto
																									.getBIZ_ATOM_NAME());
																				%>
																			
																		<tr bgcolor="#FFFFFF">
																			<td>

																				<%
																					for (int k = 0; k < mea.size(); k++) {
																								MEADTO listdto = (MEADTO) mea.get(k);
																								String value = listdto.getEND_VALUE().trim();
																								//out.print(sAtom.getAtomvalue());
																				%>

																				<input type="checkbox"
																					name="<%=dto.getBIZ_ATOM_NAME()%>"
																					value="<%=listdto.getSTART_VAULE()%>"
																					<%=(null != sAtom
												&& sAtom
														.getAtomvalue()
														.indexOf(
																listdto
																		.getSTART_VAULE()) > -1 ? "checked"
												: "")%>
																					onclick="checkItemMul('type')">
																				<%=value%>
																				<br>

																				<%
																					}

																						}

																						else if (3 == showtypeid && 300001 != dto.getBIZ_ATOM_ID()) {
																				%>
																			
																		<tr bgcolor="#FFFFFF">
																			<td>
																				<%
																					List userTree = TreeUtil.retrieveNodeInfos(dto
																									.getCDE_SRC_TABLE_NAME());
																				%>
																				<script>
					  	                                                                                <%=TreeUtil.createTreeInfo(outputList, userTree, dto
									.getBIZ_ATOM_NAME())%>
					                                                                                         </script>
																				<%
																					} else if (3 == showtypeid && 300001 == dto.getBIZ_ATOM_ID()) {
																				%>
																			
																		<tr bgcolor="#FFFFFF">
																			<td>
																				<%
																					List userFolderTree = TreeUtil.retrieveBranch_Name(latnid);
																				%>
																				<script>
					  	                                                                                <%=TreeUtil.createTreeInfo(outputList,
									userFolderTree, "地理位置细到支局")%>
					                                                                                         </script>
																				<%
																					}

																						else if (200001 == showtypeid) {

																							/*			String sql = "select * from " + tablename + " order by 1";
																										ps = con.prepareStatement(sql);

																										rs = ps.executeQuery();
																										List mea = new ArrayList();
																										while (rs != null && rs.next()) {

																									MEADTO meadto = new MEADTO();
																									meadto.setITEM_ID("");
																									meadto.setSTART_VAULE(rs.getString(1));
																									meadto.setEND_VALUE(rs.getString(2));
																									mea.add(meadto);
																										}

																										if (rs != null) {

																									rs.close();
																										}
																										if (ps != null) {
																									ps.close();
																										}*/
																							HashMap atommap = Initmap.getatomMap();

																							ArrayList mea = (ArrayList) atommap.get(dto
																									.getBIZ_ATOM_NAME());
																				%>
																			
																		<tr bgcolor="#FFFFFF">
																			<td>
																				<%
																					for (int m = 0; m < mea.size(); m++) {

																								MEADTO listdto = (MEADTO) mea.get(m);
																								String value = listdto.getEND_VALUE().trim();
																				%>

																				<input type="radio" name=<%=dto.getBIZ_ATOM_NAME()%>
																					value="<%=listdto.getSTART_VAULE()%>"
																					<%=(null != sAtom
												&& sAtom
														.getAtomvalue()
														.indexOf(
																listdto
																		.getSTART_VAULE()) > -1 ? "checked"
												: "")%>
																					onclick="checkItem('type')">
																				<%=value%>
																				<br>

																				<%
																					}

																						} else if (4 == showtypeid) {
																				%>
																				<textarea id="yhzdycx" rows="4" cols="60"
																					name="<%=dto.getBIZ_ATOM_NAME()%>"
																					title="在这里填入自定义sql语句"
																					onpropertychange="checkItemTextarea('type')"></textarea>
																				选择文本的类型:
																				<input type="radio" name="radiobutton"
																					value="Accs_Nbr" checked>
																				接入号码
																				<input type="radio" name="radiobutton"
																					value="Acct_Id">
																				账户标识
																				<input type="radio" name="radiobutton"
																					value="Cust_Id">
																				客户标识
																				<input type="radio" name="radiobutton"
																					value="prd_inst_id">
																				产品实例ID
																				<br>
																				<font color="red"><b>请在文本框填入可以得到4种id的语句或者直接用单引号包围的4种id然后选择对应的id</b>
																				</font>
																				<%
																					}

																						else if (1 == showtypeid) {
																				%>
																			
																		<tr bgcolor="#FFFFFF">
																			<td>
																				<input type="text" size="8" name="<%=dto.getBIZ_ATOM_ID() %>"
																					id="inputvalue" height="20" onkeyup="findNames()">
																				<input type="button" name="Submit" value="加入"
																					onClick="insertvalue('<%=dto.getBIZ_ATOM_NAME() %>');clearvalue()" />
																				<input type="button" name="reset" value="清空"
																					onClick="delvalue('<%=dto.getBIZ_ATOM_NAME() %>');clearvalue()">

																				<br>
																				<textarea rows="6" name="<%=dto.getBIZ_ATOM_NAME() %>" cols="18"
																					readonly="readonly"></textarea>


																				<%
																					}
																				%>
																			</td>
																		</tr>
																	</table>
																</div>
															</TD>
														</TR>
													</TABLE>
												</TD>
											</TR>
									</TABLE>
								</TD>
							</TR>
						</TABLE>
					</td>

					<%
						if ((0 == (j + 1) % 4) && j > 1) {
					%>

				</TR>
				<%
					}
				%>
				<%
					}

					for (int i = 0; i < 4 - atomlist.size() % 4; i++)
						out.print("<td></td>");

					if (session.getAttribute("APP_SUBJECT_ID") != null) {
						session.removeAttribute("APP_SUBJECT_ID");
					}
					session.setAttribute("APP_SUBJECT_ID", new Integer(0));
				%>
			</table>
			<input name="remove" id="remove" type="hidden" value="">
		</form>
	</body>
</html>
